alert('Scenehome.js loaded');
var beforeIndex = -1;
var focusIndex = 0;
var countBeforeTable = 0;
var countNextTable = 0;
var nextIndex = -1;
var countPredictTable = 0;
var predictIndex = -1;

var normalColor = "#FFFFFF";
var hilightColor = "#CCFF99";
var MODE_MAIN_PAGE = 0;
var MODE_DETAIL_PAGE = 1;
var skimMode;
var lists = [];
var listsNext = [];
var listsPredict = [];

var objFootballMatch = {};
var idInFocusIndex = -1;
var idInFocusIndexTotal = 5;

function Scenehome() {

};

Scenehome.prototype.initialize = function () {
	alert("Scenehome.initialize()");
	
		/*$.getJSON('http://thietkewebbatdongsan.com/tvapp/quanlysanbong/json/home.php', function(data) {
			for (var i=0; i < data.length; i++) {
		        jQuery("#header-container").val();
		    }
		});*/
	var url = "http://quangdung.vv.si/main.php";
	//var url = "http://quangdung.vv.si/mainserver.php";
	var table = "<table id ='beforefootballmaches' class='scheduleTable' > <tr><th>THỜI GIAN</th><th>CHỦ NHÀ</th><th>TỶ SỐ</th><th>ĐỘI KHÁCH</th></tr><tr> <td colspan='4' class='jhead'>Giai dau la liga</td></tr>";
	$.getJSON(url+'?command=loadbefore', function(data) {
		
		$.each(data.result, function(index, value) {//time. chu nha, rate, doi khach
			table +='<tr id=\'before' +index +'\'>';
				table +='<td>'+value.Thoi_Gian_Dien_Ra+'</td>';
				table +='<td>'+value.Doi_1+'</td>';
				var wina = value.Ban_Thang_Doi1;
				var winb = value.Ban_Thang_Doi2;
				table +='<td>'+wina+":"+winb+'</td>';
				
				table +='<td>'+value.Doi_2+'</td>';				
			table +='</tr>';
			objFootballMatch = {
					   Thoi_Gian_Dien_Ra : value.Thoi_Gian_Dien_Ra,
					   Doi_1 : value.Doi_1,
					   Ban_Thang_1 : value.Ban_Thang_1,
					   Doi_2 : value.Doi_2,
					   Ban_Thang_2 : value.Ban_Thang_2,		
					   MS_Tran_Dau : value.MS_Tran_Dau,					   
			   };
			lists[index] = (objFootballMatch);
			countBeforeTable++;
			alert("alrty"+index+value.Thoi_Gian_Dien_Ra+"__"+value.MS_Tran_Dau);
			//$(list).append('<li>' + value.description + ': ' + value.price + '</li>');
			   //alert(index + ":" + value.Thoi_Gian_Dien_Ra +':' +value.Doi_1 +':' +value.Ban_Thang_1);
			 
		});
		table +='</table>';
		alert("alert:"+table);
		$(table).appendTo("#posts1");
	});	
	//next
	var table1 = "<table id ='beforefootballmachesnext' class='scheduleTable' > <tr><th>THỜI GIAN</th><th>CHỦ NHÀ</th><th>TỶ LỆ</th><th>ĐỘI KHÁCH</th></tr><tr> <td colspan='4' class='jhead'>Giai dau la liga</td></tr>";
	$.getJSON(url+'?command=loadnext', function(data) {
		
		$.each(data.result, function(index, value) {//time. chu nha, rate, doi khach
			table1 +='<tr id=\'next' +index +'\'>';
				table1 +='<td>'+value.Thoi_Gian_Dien_Ra+'</td>';
				table1 +='<td>'+value.Doi_1+'</td>';
				$wina = value.Odd_A_win;
				$winb = value.Odd_B_win;
				$win = value.Odd_draw;
				if($wina==null){
					$wina = "0";
				}
				if($winb==null){
					$winb = "0";
				}
				if($win==null){
					$win = "0";
				}
				table1 +='<td>'+$wina+':'+$win+':'+$winb+'</td>';
				
				table1 +='<td>'+value.Doi_2+'</td>';				
			table1 +='</tr>';
			objFootballMatch = {
					   Thoi_Gian_Dien_Ra : value.Thoi_Gian_Dien_Ra,
					   Doi_1 : value.Doi_1,
					   Logo : value.Logo,
					   Doi_2 : value.Doi_2,
					   Ban_Thang_2 : value.Ban_Thang_2,
					   Odd_A_win : value.Odd_A_win,
					   Odd_B_win : value.Odd_B_win,
					   Odd_draw : value.Odd_draw,
					   Rate: $wina+'-'+$win+'-'+$winb,
					   Kenh : value.Kenh,
					   MS_Tran_Dau : value.MS_Tran_Dau,
			   };
			alert("ms::"+value.MS_Tran_Dau);
			listsNext[index] = (objFootballMatch);
			countNextTable++;
			//alert("....."+index+value.Thoi_Gian_Dien_Ra);
			//$(list).append('<li>' + value.description + ': ' + value.price + '</li>');
			   //alert(index + ":" + value.Thoi_Gian_Dien_Ra +':' +value.Doi_1 +':' +value.Ban_Thang_1);
			 
		});
		table1 +='</table>';
	//	alert("alert1:"+table1);
		$(table1).appendTo("#posts2");
	});
	//predict
	var table2 = "<table id ='beforefootballmachespredict' class='scheduleTable' > <tr><th>THỜI GIAN</th><th>THÀNH VIÊN</th><th>SỐ ĐIỂM</th></tr><tr> <td colspan='3' class='jhead'>TOP 5 THÀNH VIÊN DỰ ĐOÁN</td></tr>";
	$.getJSON(url+'?command=getlistpredict&codematches=401', function(data) {
		
		$.each(data.ds_3_ngay_truoc, function(index, value) {//time. chu nha, rate, doi khach
			table2 +='<tr id=\'predict' +index +'\'>';
				table2 +='<td>'+value.Thoi_Gian_Dien_Ra+'</td>';
				table2 +='<td>'+value.Doi_1+'</td>';
				
				table2 +='<td>'+value.Doi_2+'</td>';				
			table2 +='</tr>';
			objFootballMatch = {
					   Thoi_Gian_Dien_Ra : value.Thoi_Gian_Dien_Ra,
					   Doi_1 : value.Doi_1,
					   Ban_Thang_1 : value.Ban_Thang_1,
					   The_do_1 : value.The_do_1,
					   Doi_2 : value.Doi_2,
					   Ban_Thang_2 : value.Ban_Thang_2,
					   The_do_2 : value.The_do_2,
					   Link_Report : value.Link_Report,
					   Ten_Tran_Dau : value.Ten_Tran_Dau,
					   published : value.published,
			   };
			listsPredict[index] = (objFootballMatch);
			countPredictTable++;
			//alert("....."+index+value.Thoi_Gian_Dien_Ra);
			//$(list).append('<li>' + value.description + ': ' + value.price + '</li>');
			   //alert(index + ":" + value.Thoi_Gian_Dien_Ra +':' +value.Doi_1 +':' +value.Ban_Thang_1);
			 
		});
		table2 +='</table>';
		//alert("alert2:"+table2);
		$(table2).appendTo("#posts3");
	});	
	
	//ress
	var rss = 'http://www.24h.com.vn/upload/rss/bongda.rss';
	$.get(rss, function(data) {
	    var $xml = $(data);
	    $xml.find("item").each(function() {
	        var $this = $(this),
	            item = {
	                title: $this.find("title").text(),
	                link: $this.find("link").text(),
	                description: $this.find("description").text(),
	                pubDate: $this.find("pubDate").text(),
	                author: $this.find("author").text()
	        };
	       // alert(item.title+":"+item.author+":"+item.description+":"+item.link);
	       // alert("rss:"+$this.find("title").text()+":"+item.title);
	        //Do something with item here...
	    });
	}); 
	skimMode = MODE_MAIN_PAGE;
	focusIndex = 0;
	idInFocusIndex = -1;
	updateUI();
	window.fbAsyncInit = function() {
	    FB.init({
	      appId      : '628683900509984', // App ID
	      status     : true, // check login status
	      cookie     : true, // enable cookies to allow the server to access the session
	      xfbml      : true  // parse XFBML
	    });
	  };

	  // Load the SDK Asynchronously
	  (function(d){
	     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
	     if (d.getElementById(id)) {return;}
	     js = d.createElement('script'); js.id = id; js.async = true;
	     js.src = "//connect.facebook.net/en_US/all.js";
	     ref.parentNode.insertBefore(js, ref);
	     alert("load,,");
	   }(document));
	  
	 /* FB.login(function(response) {
		    if (response.authResponse) {
		        var accessToken = response.authResponse.accessToken;
		        alert(accessToken+".acc");
		    }
		    else{
		    	alert(".acc.sd");
		    }
		});*/
/*	FB.init({appId: '628683900509984', status: true, cookie: true, xfbml: true});
	  FB.Event.subscribe('auth.sessionChange', function(response) {
	    if (response.session) {
	      alert("success");
	    } else {
	    	alert("unsuccess");
	      // The user has logged out, and the cookie has been cleared
	    }
	  });*/
	// window.location.href = "http://www.24h.com.vn/bong-da/vff-bi-vo-ke-hoach-dai-hoi-vi-ung-vien-chu-tich-c48a572183.html";
	/*$(document).ready(function () {
		  $('#test').rssfeed('http://www.24h.com.vn/bong-da/dt-nu-viet-nam-co-tran-thang-dau-tien-c48a572017.html', {
		    limit: 5
		  });
		});*/
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here
	// scene HTML and CSS will be loaded before this function is called
};
function loginFB() {
	/*FB.login(function(response) {
        if (response.authResponse) {
        	alert("login..");
        	testAPI();
        } else {
        }
      });*/
	alert("login.");
	sf.scene.hide('home');
	sf.scene.show('Login');
	sf.scene.focus('Login');	
}
function registerFB() {
	alert("login.");
	sf.scene.hide('home');
	sf.scene.show('Register');
	sf.scene.focus('Register');
}
function testAPI() {
  FB.api('/me', function(response) {
    alert('Good to see you, ' + response.username + '.'+response.link);
  });
}
function login() {
	alert("sad");
    if (FB.getAuthResponse()){
        FB.api('/me', function(response) {
        	alert("..");
        //loging(response.id);
        }); 
    } 
    else{
        //user is not connected to your app or logged out
        FB.login(function(response) {
            if(response.authResponse) {
                FB.api('/me', function(response) {
                	alert("...");
                //loging(response.id);
                });
            } 
            else {
                //user cancelled login or did not grant authorization
            }
        }, {scope:'publish_stream'});   
    }
}

function loging(getuid){
    FB.api(
              {
                method: 'fql.query',
                query: 'SELECT name, uid FROM user WHERE uid=' + getuid 
              },
              function(response) {
                var user = response[0];
                jQuery.ajax({
                type: 'GET',
                url: 'login.php?uid=' + getuid,
                success: function(data) {
                    jQuery('#jstarget').html(data);
                    jQuery("#fbload").hide();
                }
                });
              }
            );        
}
Scenehome.prototype.handleShow = function (data) {
	alert("Scenehome.handleShow()");
	if(data=="return"){
		alert("return nha");
		skimMode = MODE_MAIN_PAGE;
		/*skimMode = MODE_MAIN_PAGE;
		focusIndex = 0;
		idInFocusIndex = -1;
		beforeIndex = -1;
		focusIndex = 0;
		countBeforeTable = 0;
		countNextTable = 0;
		nextIndex = -1;
		countPredictTable = 0;
		predictIndex = -1;
		idInFocusIndex = -1;
		idInFocusIndexTotal = 5;
		updateUI();*/
	}else{
	
	}
	//loginFB();
	// this function will be called when the scene manager show this scene
};
function fbs_click(width, height) {
    var leftPosition, topPosition;
    leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
    topPosition = (window.screen.height / 2) - ((height / 2) + 50);
    var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no";
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer', windowFeatures);
    return false;
}
function resetBannerOutstadding() {
	var i;
	for(i=0;i<idInFocusIndexTotal;i++){
		$('#imageoutstanding'+i).css('border-top', 'solid 0px');
		$('#imageoutstanding'+i).css('border-left', 'solid 0px');
		$('#imageoutstanding'+i).css('border-right', 'solid 0px');
		$('#imageoutstanding'+i).css('border-bottom', 'solid 0px');
		
	}
}

function updateUI() {
	if(focusIndex==0){
		switch (idInFocusIndex) {
		case 0:
		case -1:
			//$('#imageoutstanding1').css('border-bottom', 'solid 4px red');
			$('#imageoutstanding0').css('border-top', 'solid 4px red');
			//$('#imageoutstanding1').css('border-left', 'solid 4px red');
			//$('#imageoutstanding1').css('border-right', 'solid 4px red');
			break;
		case 1:
			//$('#imageoutstanding1').css('border-bottom', 'solid 4px red');
			$('#imageoutstanding1').css('border-top', 'solid 4px red');
			//$('#imageoutstanding1').css('border-left', 'solid 4px red');
			//$('#imageoutstanding1').css('border-right', 'solid 4px red');
			break;
		case 2:
			//$('#imageoutstanding2').css('border-bottom', 'solid 4px red');
			$('#imageoutstanding2').css('border-top', 'solid 4px red');
			///$('#imageoutstanding2').css('border-left', 'solid 4px red');
			//$('#imageoutstanding2').css('border-right', 'solid 4px red');
			break;
		case 3:
			//$('#imageoutstanding3').css('border-bottom', 'solid 4px red');
			$('#imageoutstanding3').css('border-top', 'solid 4px red');
			//$('#imageoutstanding3').css('border-left', 'solid 4px red');
			//$('#imageoutstanding3').css('border-right', 'solid 4px red');
			break;
		case 4:
			//$('#imageoutstanding4').css('border-bottom', 'solid 4px red');
			$('#imageoutstanding4').css('border-top', 'solid 4px red');
			//$('#imageoutstanding4').css('border-left', 'solid 4px red');
			//$('#imageoutstanding4').css('border-right', 'solid 4px red');
			break;

		default:
			break;
		}
	}
}
Scenehome.prototype.handleHide = function () {
	alert("Scenehome.handleHide()");
	// this function will be called when the scene manager hide this scene
};

Scenehome.prototype.handleFocus = function () {
	alert("Scenehome.handleFocus()");
	// this function will be called when the scene manager focus this scene
};

Scenehome.prototype.handleBlur = function () {
	alert("Scenehome.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
	
};

Scenehome.prototype.handleKeyDown = function (keyCode) {
	alert("Scenehome.handleKeyDown(" + keyCode + ")");
	//var positions = [ 0,600, 1000,1500];
	// TODO : write an key event handler when this scene get focued
	switch (keyCode) {
		case sf.key.LEFT:
			alert('left');
			//jscrollPrev(positions);
			resetEnableFocusTableCellBeforeFootballMaches();
			enableFocusTableBeforeFootballMaches("false");
			focusIndex--;
			//fbs_click(300, 300);
			/*if(focusIndex==0){
				updateUI();
			}*/
			if(focusIndex==1){//table before
				beforeIndex = 0;
				$("#beforefootballmaches").focus();
				resetEnableFocusTableCellBeforeFootballMaches2();
				enableFocusTableBeforeFootballMaches2("false");	
				resetBannerOutstadding();
				//$("#posts").css("border-bottom-color", "#ff0000");
				enableFocusTableBeforeFootballMaches("true");
				jscrollTo(700,700);
			}
			if(focusIndex==2){//table next
				nextIndex = 0;
				$("#beforefootballmachesnext").focus();
				resetEnableFocusTableCellBeforeFootballMaches3();
				enableFocusTableBeforeFootballMaches3("false");				
				//$("#posts").css("border-bottom-color", "#ff0000");
				enableFocusTableBeforeFootballMaches2("true");
				jscrollTo(1200,1200);
			}
			if(focusIndex<0){
				focusIndex = 3;
			}
			if(focusIndex==3){//table predict
				predictIndex = 0;
				resetBannerOutstadding();		
				//$("#posts").css("border-bottom-color", "#ff0000");
				enableFocusTableBeforeFootballMaches3("true");
				jscrollTo(1700,1700);
			}
			
			if(focusIndex==0){//table outstanding
				idInFocusIndex = -1;
				$("#beforefootballmaches").focus();
				resetEnableFocusTableCellBeforeFootballMaches();
				enableFocusTableBeforeFootballMaches("false");	
				resetBannerOutstadding();
				updateUI();
				jscrollTo(00,00);
				//$("#posts").css("border-bottom-color", "#ff0000");
				//enableFocusTableBeforeFootballMaches("true");
			}
			//if(focusIndex!=2)
			//jscrollPrev(positions);			
			
			break;
		case sf.key.RIGHT:
			alert("right nha");
			focusIndex++;
			if(focusIndex==1){//table before
				beforeIndex = -1;
				$("#beforefootballmaches").focus();
				resetBannerOutstadding();
				//$("#posts").css("border-bottom-color", "#ff0000");
				enableFocusTableBeforeFootballMaches("true");
				jscrollTo(700,700);
			}
			if(focusIndex==2){//table next
				nextIndex = -1;
				$("#beforefootballmachesnext").focus();
				resetEnableFocusTableCellBeforeFootballMaches();
				enableFocusTableBeforeFootballMaches("false");				
				//$("#posts").css("border-bottom-color", "#ff0000");
				enableFocusTableBeforeFootballMaches2("true");
				jscrollTo(1200,1200);
			}
			if(focusIndex==3){//table predict
				predictIndex = -1;
				resetEnableFocusTableCellBeforeFootballMaches2();
				enableFocusTableBeforeFootballMaches2("false");				
				//$("#posts").css("border-bottom-color", "#ff0000");
				enableFocusTableBeforeFootballMaches3("true");
				jscrollTo(1700,1700);
			}
			//if(focusIndex!=3)
				//jscrollNext(positions);
			
				if(focusIndex==4){
					focusIndex = 0;
					jscrollTo(0,0);
				}
			if(focusIndex==0){//table outstanding
				idInFocusIndex = -1;
				$("#beforefootballmaches").focus();
				resetEnableFocusTableCellBeforeFootballMaches3();
				enableFocusTableBeforeFootballMaches3("false");	
				resetBannerOutstadding();
				updateUI();
				//jscrollTo(100,100);
				//$("#posts").css("border-bottom-color", "#ff0000");
				//enableFocusTableBeforeFootballMaches("true");
			}
			
			break;
		case sf.key.UP:
			//jscrollDown(0);
			if(focusIndex==0){
				idInFocusIndex--;
				if(idInFocusIndex<0){
					idInFocusIndex = idInFocusIndexTotal-1;
				}
				resetBannerOutstadding();
				updateUI();
			}
			if(focusIndex==1){
				$('#before'+beforeIndex).focus();
				//$("#posts").css("border-bottom-color", "#ff0000");
				beforeIndex--;
				if(beforeIndex<0){
					beforeIndex = countBeforeTable-1;					
				}
				//enableFocusTableBeforeFootballMaches("false");
				resetEnableFocusTableCellBeforeFootballMaches();
				enableFocusTableCellBeforeFootballMaches("true");
				
			}
			if(focusIndex==2){
				$('#next'+nextIndex).focus();
				//$("#posts").css("border-bottom-color", "#ff0000");
				nextIndex--;
				if(nextIndex<0){
					nextIndex = countNextTable-1;					
				}
				//enableFocusTableBeforeFootballMaches("false");
				resetEnableFocusTableCellBeforeFootballMaches2();
				enableFocusTableCellBeforeFootballMaches2("true");
				
			}
			if(focusIndex==3){
				$('#predict'+predictIndex).focus();
				//$("#posts").css("border-bottom-color", "#ff0000");
				predictIndex--;
				if(predictIndex<0){
					predictIndex = countPredictTable-1;					
				}
				//enableFocusTableBeforeFootballMaches("false");
				resetEnableFocusTableCellBeforeFootballMaches3();
				enableFocusTableCellBeforeFootballMaches3("true");
				
			}
			break;
		case sf.key.DOWN:
			//jscrollDown(200);
			if(focusIndex==0){
				idInFocusIndex++;
				if(idInFocusIndex==idInFocusIndexTotal){
					idInFocusIndex = 0;
				}
				resetBannerOutstadding();
				updateUI();
			}
			if(focusIndex==1){
				$('#before'+beforeIndex).focus();
				//$("#posts").css("border-bottom-color", "#ff0000");
				beforeIndex++;
				if(beforeIndex==countBeforeTable){//3
					beforeIndex = 0;
				}
				//enableFocusTableBeforeFootballMaches("false");
				resetEnableFocusTableCellBeforeFootballMaches();
				enableFocusTableCellBeforeFootballMaches("true");				
				
			}
			if(focusIndex==2){
				$('#next'+nextIndex).focus();
				//$("#posts").css("border-bottom-color", "#ff0000");
				nextIndex++;
				if(nextIndex==countNextTable){//3
					nextIndex = 0;
				}
				//enableFocusTableBeforeFootballMaches("false");
				resetEnableFocusTableCellBeforeFootballMaches2();
				enableFocusTableCellBeforeFootballMaches2("true");				
				
			}
			if(focusIndex==3){
				$('#predict'+predictIndex).focus();
				//$("#posts").css("border-bottom-color", "#ff0000");
				predictIndex++;
				if(predictIndex==countPredictTable){//3
					predictIndex = 0;
				}
				//enableFocusTableBeforeFootballMaches("false");
				resetEnableFocusTableCellBeforeFootballMaches3();
				enableFocusTableCellBeforeFootballMaches3("true");				
				
			}
			alert("down");
			break;
		case sf.key.ENTER:
			alert("doi:"+focusIndex+":"+skimMode);
			if(focusIndex==2 && skimMode == MODE_MAIN_PAGE){
				//var detailPicture = lists[beforeIndex].Doi_1+":"+lists[beforeIndex].Doi_2+":"+lists[beforeIndex].Thoi_Gian_Dien_Ra;
			//	var detailPicture = listsNext[nextIndex].Doi_1+":"+listsNext[nextIndex].Doi_2+":"+listsNext[nextIndex].Thoi_Gian_Dien_Ra+":"+listsNext[nextIndex].Rate;
				//alert("doi:"+detailPicture.Doi_1);
				//var l = [lists[beforeIndex].Doi_1,lists[beforeIndex].Doi_2,lists[beforeIndex].Thoi_Gian_Dien_Ra,lists[beforeIndex].MS_Tran_Dau];
				var l = [listsNext[nextIndex].Doi_1,listsNext[nextIndex].Doi_2,listsNext[nextIndex].Thoi_Gian_Dien_Ra,listsNext[nextIndex].MS_Tran_Dau,listsNext[nextIndex].Rate];
				alert("ms:"+l[4]);
				//	alert(lists[beforeIndex].MS_Tran_Dau+"..a");
				sf.scene.hide('home');
				sf.scene.show('sub', l);
				sf.scene.focus('sub');
			}
			if(focusIndex==1 && skimMode == MODE_MAIN_PAGE){
				//var detailPicture = lists[beforeIndex].Doi_1+":"+lists[beforeIndex].Doi_2+":"+lists[beforeIndex].Thoi_Gian_Dien_Ra;
			//	var detailPicture = listsNext[nextIndex].Doi_1+":"+listsNext[nextIndex].Doi_2+":"+listsNext[nextIndex].Thoi_Gian_Dien_Ra+":"+listsNext[nextIndex].Rate;
				//alert("doi:"+detailPicture.Doi_1);
				var l = [lists[beforeIndex].Doi_1,lists[beforeIndex].Doi_2,lists[beforeIndex].Thoi_Gian_Dien_Ra,lists[beforeIndex].MS_Tran_Dau,lists[beforeIndex].Rate];
				//var l = [listsNext[nextIndex].Doi_1,listsNext[nextIndex].Doi_2,listsNext[nextIndex].Thoi_Gian_Dien_Ra,listsNext[nextIndex].MS_Tran_Dau,listsNext[nextIndex].Rate];
				//alert("ms:"+l[4]);
				//	alert(lists[beforeIndex].MS_Tran_Dau+"..a");
				sf.scene.hide('home');
				sf.scene.show('subPredicted', l);
				sf.scene.focus('subPredicted');
			}
			break;
		case sf.key.KEY_EXIT:
			var widgetAPI = new Common.API.Widget(); 
		    widgetAPI.sendExitEvent();
			break;
		default:
			alert("handle default key event, key code(" + keyCode + ")");
			break;
	}
};
function enableFocusTableBeforeFootballMaches(data) {
	if(data=="true"){
		$('#beforefootballmaches').css('border-bottom', 'solid 3px red');
		$('#beforefootballmaches').css('border-top', 'solid 3px red');
		$('#beforefootballmaches').css('border-left', 'solid 3px red');
		$('#beforefootballmaches').css('border-right', 'solid 3px red');
	}
	else{
		$('#beforefootballmaches').css('border-bottom', 'solid 0px');
		$('#beforefootballmaches').css('border-top', 'solid 0px');
		$('#beforefootballmaches').css('border-left', 'solid 0px');
		$('#beforefootballmaches').css('border-right', 'solid 0px');
	}
}
function enableFocusTableBeforeFootballMaches2(data) {
	if(data=="true"){
		$('#beforefootballmachesnext').css('border-bottom', 'solid 3px red');
		$('#beforefootballmachesnext').css('border-top', 'solid 3px red');
		$('#beforefootballmachesnext').css('border-left', 'solid 3px red');
		$('#beforefootballmachesnext').css('border-right', 'solid 3px red');
	}
	else{
		$('#beforefootballmachesnext').css('border-bottom', 'solid 0px');
		$('#beforefootballmachesnext').css('border-top', 'solid 0px');
		$('#beforefootballmachesnext').css('border-left', 'solid 0px');
		$('#beforefootballmachesnext').css('border-right', 'solid 0px');
	}
}
function enableFocusTableBeforeFootballMaches3(data) {
	if(data=="true"){
		$('#beforefootballmachespredict').css('border-bottom', 'solid 3px red');
		$('#beforefootballmachespredict').css('border-top', 'solid 3px red');
		$('#beforefootballmachespredict').css('border-left', 'solid 3px red');
		$('#beforefootballmachespredict').css('border-right', 'solid 3px red');
	}
	else{
		$('#beforefootballmachespredict').css('border-bottom', 'solid 0px');
		$('#beforefootballmachespredict').css('border-top', 'solid 0px');
		$('#beforefootballmachespredict').css('border-left', 'solid 0px');
		$('#beforefootballmachespredict').css('border-right', 'solid 0px');
	}
}
function enableFocusTableCellBeforeFootballMaches(data) {
	if(data=="true"){
		$('#before'+beforeIndex).css("background-color", "#FF0000");
		/*$('#before'+beforeIndex).css('border-top', 'solid 1px red');
		$('#before'+beforeIndex).css('border-left', 'solid 1px red');
		$('#before'+beforeIndex).css('border-right', 'solid 1px red');*/
	}
	else{
		$('#before'+beforeIndex).css("background-color", "#FFFFFF");
		/*$('#before'+beforeIndex).css('border-top', 'solid 0px');
		$('#before'+beforeIndex).css('border-left', 'solid 0px');
		$('#before'+beforeIndex).css('border-right', 'solid 0px');*/
	}
}
function enableFocusTableCellBeforeFootballMaches2(data) {
	if(data=="true"){
		$('#next'+nextIndex).css("background-color", "#FF0000");
		/*$('#before'+beforeIndex).css('border-top', 'solid 1px red');
		$('#before'+beforeIndex).css('border-left', 'solid 1px red');
		$('#before'+beforeIndex).css('border-right', 'solid 1px red');*/
	}
	else{
		$('#next'+nextIndex).css("background-color", "#FFFFFF");
		/*$('#before'+beforeIndex).css('border-top', 'solid 0px');
		$('#before'+beforeIndex).css('border-left', 'solid 0px');
		$('#before'+beforeIndex).css('border-right', 'solid 0px');*/
	}
}
function enableFocusTableCellBeforeFootballMaches3(data) {
	if(data=="true"){
		$('#predict'+predictIndex).css("background-color", "#FF0000");
		/*$('#before'+beforeIndex).css('border-top', 'solid 1px red');
		$('#before'+beforeIndex).css('border-left', 'solid 1px red');
		$('#before'+beforeIndex).css('border-right', 'solid 1px red');*/
	}
	else{
		$('#predict'+predictIndex).css("background-color", "#FFFFFF");
		/*$('#before'+beforeIndex).css('border-top', 'solid 0px');
		$('#before'+beforeIndex).css('border-left', 'solid 0px');
		$('#before'+beforeIndex).css('border-right', 'solid 0px');*/
	}
}
function resetEnableFocusTableCellBeforeFootballMaches() {	
	var i;
	for(i=0;i<countBeforeTable;i++){
		$('#before'+i).css("background-color", "#FFFFFF");
	}
}
function resetEnableFocusTableCellBeforeFootballMaches2() {	
	var i;
	for(i=0;i<countBeforeTable;i++){
		$('#next'+i).css("background-color", "#FFFFFF");
	}
}
function resetEnableFocusTableCellBeforeFootballMaches3() {	
	var i;
	for(i=0;i<countBeforeTable;i++){
		$('#predict'+i).css("background-color", "#FFFFFF");
	}
}
function showMessage(msg) {
	  // alert(msg);		
		resetEnableFocusTableCellBeforeFootballMaches2();
		enableFocusTableBeforeFootballMaches2("false");	
		resetEnableFocusTableCellBeforeFootballMaches3();
		enableFocusTableBeforeFootballMaches3("false");
		resetEnableFocusTableCellBeforeFootballMaches();
		enableFocusTableBeforeFootballMaches("false");
		focusIndex = 0;
		idInFocusIndex = -1;
		updateUI();
	   jscrollTo( 0, 0, {queue:true} );
	  
};
function showPredict() {
	sf.scene.hide('home');
	sf.scene.show('sub', "predict");
	sf.scene.focus('sub');	
};